Ext.define('DragonApp.view.Server', {
    extend: 'DragonApp.view.foundation.Grid',

    alias: ['widget.server'],

    requires: [
        'DragonApp.view.Server',
        'DragonApp.store.JsonPServer'
    ],

    store: {
        type: 'jsonPServerStore',
        storeId : 'jsonPServerStore'
    },

    selModel: {
      selType: 'checkboxmodel'
    },

    controller: 'server',

    columns: [
        { text: 'ID', dataIndex: 'id', align: 'center', width: 100 },
        { text: '服务器名称', dataIndex: 'hostname', align: 'center', width: 100 },
        { text: 'IP', dataIndex: 'hostip', align: 'center', width: 140 },
        { text: '状态', dataIndex: 'status', align: 'center', width: 100, renderer: 'statusRender' },
        { text: '开服时间', dataIndex: 'open_at', align: 'center', width: 144 },
        { text: '备注', dataIndex: 'comments', align: 'center', flex: 1 },
        {
          xtype:'actioncolumn', width:150,  align:'center',  text: '服务器操作', itemId : 'actioncolumn',
          items: [{
            iconCls: 'x-fa fa-youtube-play',
            tooltip: '开服',
            itemId : 'OPEN',
            handler: 'onServerOperationReq',
            margin: '0 10 0 0'
          },
          {
            iconCls: 'x-fa fa-ban',
            tooltip: '关服',
            itemId : 'CLOSE',
            handler: 'onServerOperationReq',
            margin: '0 10 0 0'
          },{
            iconCls: 'x-fa fa-minus-square',
            tooltip: '停服',
            itemId : 'PAUSE',
            handler: 'onServerOperationReq'
          }]
        }
    ],

    initComponent: function() {
        var me = this;
        me.tbar = [
            {
                xtype: 'button',
                text: '新增服务器',
                itemId: 'new',
                tooltip: '新增服务器',
                handler: 'onAdd',
                iconCls: 'x-fa fa-plus-circle',
                width: 120
            }, '->',
            {
                xtype: 'button',
                text: '批量开服',
                itemId: 'open',
                tooltip: '批量开服',
                handler: 'onBatRequest',
                iconCls: 'x-fa fa-youtube-play',
                width: 100
            },{
                xtype: 'button',
                text: '批量关服',
                itemId: 'close',
                tooltip: '批量关服',
                handler: 'onBatRequest',
                iconCls: 'x-fa fa-ban',
                width: 100
            },{
                xtype: 'button',
                text: '批量停服',
                itemId: 'pause',
                tooltip: '批量停服',
                handler: 'onBatRequest',
                iconCls: 'x-fa fa-minus-square',
                width: 100
            }
        ];
        me.callParent(arguments);
        //========
        //权限控制
        //========
        if ('查询用户' == sessionStorage.getItem("DragonApp_role_name")) {

            me.queryById('new').hide();
            me.queryById('open').hide();
            me.queryById('close').hide();
            me.queryById('pause').hide();
            me.queryById('edit').hide();
            me.queryById('delete').hide();
            me.queryById('actioncolumn').hide();
        }
    },
    listeners: {
        beforerender: function(me) {
            var store = me.getStore();
            store.load();
        }
    }
});